/*
* 公共执行http请求
* */
import api from './api'
import request from './request'
import { codeSuccess, codeError } from './helper'

const { test } = api

export async function getUser ({ params, cb }) {
  const { msg, data } = await request.apiGet(test, params || {})
  if (msg && msg.code === '20000') {
    codeSuccess()
    cb(msg, data)
  } else {
    codeError()
  }
}

export async function getTrafficNetWork ({ cb }) {
  const data = await request.apiGet(api.busNetWork)
  cb(data)
}
// 运营车辆数据
export async function getTrafficBusLocation ({ cb }) {
  const data = await request.apiGet(api.busLocation)
  cb(data)
}
// 热力图数据
export async function getTrafficHeatmap({ cityCode }) {
  return await request.apiGet(api.heatMap, {cityCode: cityCode})
}
// 停车场数据
export async function getParkingInfo(cityCode) {
  return await request.apiGet(api.parkingInfo, {cityCode: cityCode})
}
// 获取营收趋势7天数据
export async function getAmountLine (cityCode) {
  const data = await request.apiGet(api.amountLine, {cityCode: cityCode})
  return data
}
// 获取里程数据7天数据
export async function getMileageLine (cityCode) {
  const data = await request.apiGet(api.mileageLine, {cityCode: cityCode})
  return data
}
// 获取客流数据7天数据
export async function getUserFlowLine (cityCode) {
  const data = await request.apiGet(api.userFlowLine, {cityCode: cityCode})
  return data
}
// 获取车辆报警数据
export async function getBusWarnPie (cityCode) {
  const data = await request.apiGet(api.busWarnPie, {cityCode: cityCode})
  return data
}
// 获取昨日收入/里程/客流数据
export async function getYesterdayData (cityCode) {
  const data = await request.apiGet(api.yestodayData, {cityCode: cityCode})
  return data
}
// 获取车辆运营数据
export async function getOperateData (cityCode) {
  const data = await request.apiGet(api.operateData, {cityCode: cityCode})
  return data
}
// 获取互联网用户数据
export async function getNetworkData (cityCode) {
  const data = await request.apiGet(api.networkData, {cityCode: cityCode})
  return data
}
// 获取实时里程数
export async function getIntevalMileage (cityCode) {
  const data = await request.apiGet(api.intervalMileage, {cityCode: cityCode})
  return data
}
// 获取七日平均客流量
export async function getAvarageUserFlow (cityCode) {
  const data = await request.apiGet(api.averageUser, {cityCode: cityCode})
  return data
}
